package com.sxkj.web.controller.sys;

import com.github.pagehelper.PageInfo;
import com.sxkj.common.response.ResponseResult;
import com.sxkj.entity.base.Page;
import com.sxkj.entity.entity.sys.Dict;
import com.sxkj.service.sys.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @title: DictController
 * @author: daixiaowei
 * @date: 2019年12月23日 下午 05:42:25
 * @description: 字典项查询
 */
@Controller
@Api(tags = "DictController", description = "菜单接口")
@RequestMapping("/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    /**
     *
     * @title: searchDicTree
     * @author: daixiaowei
     * @date: 2019年12月23日 下午 07:18:46
     * @description: 查询字典项列表
     * @param:
     * @return:
     */
    @ApiOperation(value = "查询字典项列表")
    @RequestMapping(value = "/searchDicTree", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult searchDicTree(@RequestParam(value =
            "dicType") String dicType,@RequestParam(value =
            "pageSize",defaultValue = "10") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return ResponseResult.success(Page.restPage(dictService.searchListPage(dicType, pageSize, pageNum)));
    }

    /**
     *
     * @title: searchDict
     * @author: daixiaowei
     * @date: 2019年12月23日 下午 07:19:00
     * @description: 查询字典
     * @param:
     * @return:
     */
    @ApiOperation(value = "查询字典")
    @RequestMapping(value = "/searchDict", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult searchDict(@RequestParam(value =
            "id") String id) throws Exception {
        return ResponseResult.success(dictService.get(id));
    }

    /**
     *
     * @title: addDict
     * @author: daixiaowei
     * @date: 2019年12月23日 下午 07:25:42
     * @description: 字典新增
     * @param: dict
     * @return:
     */
    @ApiOperation(value = "字典新增")
    @RequestMapping(value = "/addDict", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult addDict(@RequestBody Dict dict, BindingResult result) throws Exception{
        dictService.add(dict);
        return ResponseResult.success();
    }

    /**
     *
     * @title: deleteDict
     * @author: daixiaowei
     * @date: 2019年12月23日 下午 07:48:41
     * @description: 删除
     * @param: dict
     * @return: 
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/deleteDict", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteDict(@RequestBody  Dict dict, BindingResult result) {
        dictService.deleteDictById(dict.getId());
        return ResponseResult.success();
    }
}
